﻿using MobaCommon.Code;
using MobaCommon.Dto;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using LitJson;

public class LoginView : MonoBehaviour
{
    #region 注册模块
    [Header("注册模块")]
    [SerializeField]
    private InputField registeraAccountInput;
    [SerializeField]
    private InputField registerPwdInput;
    [SerializeField]
    private InputField registerSubmitPwdInput;

    /// <summary>
    /// 点击注册
    /// </summary>
    public void OnRegister()
    {
        if (string.IsNullOrEmpty(registeraAccountInput.text) || string.IsNullOrEmpty(registerPwdInput.text)
            || !registerPwdInput.text.Equals(registerSubmitPwdInput.text))
        {
            return;
        }
        string account = registeraAccountInput.text;
        string password = registerPwdInput.text;
        PhotonManager.Instance.Request(OpCode.AccountCode, OpAccount.Register, account, password);
    }

    #endregion

    #region 登陆模块
    [Header("登陆模块")]
    [SerializeField]
    private InputField loginAccountInput;
    [SerializeField]
    private InputField loginPwdInput;

    /// <summary>
    /// 进入游戏
    /// </summary>
    public void OnEnterGame()
    {
        if (string.IsNullOrEmpty(loginAccountInput.text) || string.IsNullOrEmpty(loginPwdInput.text))
        {
            //提示
            return;
        }

        AccountDto dto = new AccountDto()
        {
            Account = loginAccountInput.text,
            Password = loginPwdInput.text
        };
        PhotonManager.Instance.Request(OpCode.AccountCode, OpAccount.Login, JsonMapper.ToJson(dto));
    }

    #endregion
}
